package cn.easier.activity.console.quartz;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author lixiaopeng
 */
@Component
public class LogRestoreTask {
    private static Logger log = LoggerFactory.getLogger(LogRestoreTask.class);

    @Resource
    private LogsRestore logsRestore;

    /**
     * 定时任务每天零点凌晨6点进行日志读取并计算入库     0 0 6 * * ?
     * 0 0/5 * * * ?  每五分钟执行一次
     */
    @Scheduled(cron = "0 0 6 * * ?")
    public void logPvUvCount() {
        try {
            long startTime = System.currentTimeMillis();
            log.info("logPvUvCount begin");
            logsRestore.findActivities();
            logsRestore.restoreLog();
            logsRestore.LogsCount();
            log.info("Task: logPvUvCount successful, time usage: {}ms", System.currentTimeMillis() - startTime);
        } catch (Exception e) {
            e.printStackTrace();
            log.info("服务异常=>{}", e.getMessage());
        }
    }


}
